import os

# 1.编译器
env = Environment()
# clang编译器
# env = Environment(tools = ['default', 'clang'])
# env['CC']=['clang']
# env['CXX']=['clang++']

# 2.ros版本 include + lib
ros_distro=os.getenv("ROS_DISTRO")
print('env ros',ros_distro)
ros_include = ' -I /opt/ros/%s/include/'%(ros_distro)
ros_libdir = ['/opt/ros/%s/lib'%(ros_distro)]
ros_lib_dep = ['roscpp','rosconsole']

def auto_get_ros_dir():
    filePath=os.getcwd()
    idx = filePath.find('src')
    project_dir = filePath[0:idx]
    print("项目位置:%s"%(project_dir))
    return project_dir

# 3.ros项目路径 msg,srv include + lib
project_dir = auto_get_ros_dir()
project_dev = project_dir+'devel/'                              # 自动获取ros devel路径
# userName=os.getenv("USER")
# project_dev='/home/%s/3_work/3_navigation/devel/'%(userName)  # 填写完整ros devel路径
project_include = ' -I '+project_dev+'include'
project_libdir = [project_dev+'lib']

# 4.自己库 include + 链接库名
self_lib_include = ' -I'+project_dir+'src/1_ros_基础/21_ros动态库/lib_test/include/'
ros_lib_dep += ['liblib_test']

# -------------------------------
# -------------------------------
# <1编译选项
env['CCFLAGS'] = ros_include + project_include + self_lib_include
env['CCFLAGS'] += ' -ggdb3 -O0 -DDEBUG'         # 调试选项开关

# <2链接选项
env['LIBPATH'] = ros_libdir + project_libdir
env['RPATH'] = ros_libdir + project_libdir
env['LIBS'] = ros_lib_dep
env['LINKFLAGS'] = '-Wl,--copy-dt-needed-entries'

# <3编译
src=['main.cpp']
env.Program('main.out', src)